package com.example.compose_learn.views

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatButton
import com.example.compose_learn.R

class MyButton @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : AppCompatButton(context, attrs, defStyleAttr) {

    private var buttonColor: Int = Color.BLUE // 默认颜色

    init {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyButton)
        buttonColor = typedArray.getColor(R.styleable.MyButton_buttonColor, buttonColor)
        typedArray.recycle()

        // 设置按钮背景颜色
        setBackgroundColor(buttonColor)
    }

    // ... 其他代码 ...
}